// This is the testbench used to run the packed array version top design

module strategy_tb;

localparam int NUM_CONTRACTS = 3;
logic clk_net, rst_n;

logic [NUM_CONTRACTS-1:0][31:0] bbo_bidprice, bbo_askprice;
logic [NUM_CONTRACTS-1:0][7:0]  bbo_bidvolume, bbo_askvolume;
logic [NUM_CONTRACTS-1:0]       bbo_changed;
logic [NUM_CONTRACTS-1:0][31:0] rels;

logic [NUM_CONTRACTS-1:0]       send_order_vld;
logic [NUM_CONTRACTS-1:0][31:0] send_order_price;
logic [NUM_CONTRACTS-1:0]       send_order_buy;

strategy UUT ( .* );

    // Initialise clock
    initial clk_net = 0;
    always #5 clk_net = ~clk_net;

    integer i;
    initial begin

        $dumpfile("strategy_tb.vcd");
        $dumpvars(0,UUT);

        rst_n = 0;
        for (i = 0; i < NUM_CONTRACTS; i++) begin
            bbo_bidprice[i]  = 0;
            bbo_askprice[i]  = 0;
            bbo_bidvolume[i] = 0;
            bbo_askvolume[i] = 0;
            bbo_changed[i]   = 0;
            rels[i]          = 0;
        end
        rels[0] = 0;
        rels[1] = 25;
        rels[2] = 10;

        #10 rst_n = 1;
        // Initialise FV for Royal Gala and send bbo_changed signal
        #50;
        bbo_bidvolume[0] = 13;
        bbo_bidprice[0] =  2500;
        bbo_askvolume[0] = 3;
        bbo_askprice[0] = 2505;
        bbo_changed[0] = 1;

        #10 bbo_changed[0] = 0;

        // Example 1 from the task description file
        // BBO for Granny Smith apples is 2 2520 | 2530 3
        // Should send buy order

        #50;
        bbo_bidvolume[1] = 2;
        bbo_bidprice[1] =  2520;
        bbo_askvolume[1] = 3;
        bbo_askprice[1] = 2528;
        bbo_changed[1] = 1;

        #20 bbo_changed[1] = 0;

        // Example 2 from the task description file
        // BBO for Granny Smith apples is 2 2520 | 2528 3 and change to 1 2510 | 2535 3
        // It should not send any orders
        #50;
        bbo_bidvolume[1] = 1;
        bbo_bidprice[1] =  2510;
        bbo_askvolume[1] = 3;
        bbo_askprice[1] = 2530;
        bbo_changed[1] = 1;

        #10 bbo_changed[1] = 0;

        // Test example 3
        // BBO for Granny Smith apples is 2 2520 | 2528 3 and change to 1 2510 | 2535 3
        // Should sell orders
        #50;
        bbo_bidvolume[1] = 1;
        bbo_bidprice[1] =  2540;
        bbo_askvolume[1] = 3;
        bbo_askprice[1] = 2530;
        bbo_changed[1] = 1;

        #10 bbo_changed[1] = 0;

        // Test example 4
        // BBO for Fuji set to 4 2525 | 2530 3
        // Should sell orders
        #50;
        bbo_bidvolume[2] = 4;
        bbo_bidprice[2] =  2525;
        bbo_askvolume[2] = 3;
        bbo_askprice[2] = 2530;
        bbo_changed[2] = 1;

        #10 bbo_changed[2] = 0;

        // Test example 5
        // Reset FV
        // Should not send any orders
        bbo_bidvolume[0] = 13;
        bbo_bidprice[0] =  2505;
        bbo_askvolume[0] = 3;
        bbo_askprice[0] = 2505;
        bbo_changed[0] = 1;

        #10 bbo_changed[0] = 0;

        // Test example 6
        // BBO for Fuji set to 4 2525 | 2510 3
        // Should buy orders
        #50;
        bbo_bidvolume[2] = 4;
        bbo_bidprice[2] =  2525;
        bbo_askvolume[2] = 3;
        bbo_askprice[2] = 2510;
        bbo_changed[2] = 1;
        
        #10 bbo_changed[2] = 0;

        // Test negative logic reset
        #20 rst_n = 0;
        #10;
        
        $finish;
    end

endmodule